package astudy.blog;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;

import com.sun.syndication.feed.synd.SyndCategory;
import com.sun.syndication.feed.synd.SyndContent;
import com.sun.syndication.feed.synd.SyndEntry;
import com.sun.syndication.feed.synd.SyndFeed;
import com.sun.syndication.io.FeedException;
import com.sun.syndication.io.SyndFeedInput;
import com.sun.syndication.io.XmlReader;

@SuppressWarnings("unchecked")
public class RomeTest {

	public static void main(String[] args) 
	throws IllegalArgumentException, MalformedURLException, FeedException, IOException {

		String url = "http://feed.mxjava.com/";
		SyndFeedInput input = new SyndFeedInput();
		SyndFeed feed = input.build(new XmlReader(new URL(url)));
		System.out.println("=========FEED=========");
		System.out.println(feed.getTitle());
		System.out.println(feed.getAuthor());
		System.out.println(feed.getDescription());
		System.out.println(feed.getLinks());

		List<SyndEntry> list = feed.getEntries();
		if (list != null && !list.isEmpty()) {
			for (SyndEntry entry : list) {
				System.out.println("===" + entry.getTitle() + " By " + entry.getAuthor());
				System.out.println(entry.getUri() + " published: " + entry.getPublishedDate());
				for (SyndCategory sc: (List<SyndCategory>)entry.getCategories()) {
					System.out.println(sc.getName());					
				}
				for (SyndContent sc: (List<SyndContent>)entry.getContents()) {
					System.out.println("CONTENT MODE: " + sc.getMode());
					System.out.println("CONTENT TYPE: " + sc.getType());
					System.out.println(sc.getValue());					
				}
			}
		}
	}
}
